package com.ztt.controller.admin;

import com.ztt.pojo.entity.zttEmployee;
import com.ztt.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "员工接口")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;



    @ApiOperation("查询所有员工")
    @GetMapping("/selectAllEmployee")
    public List<zttEmployee> selectAllEmployee(){
        return employeeService.selectAllEmployee();
    };

    //新增
    @ApiOperation(value = "增加员工")
    @PostMapping("/insertEmployee")
    public String insertEmployee(@RequestBody zttEmployee employee){
        employeeService.insertEmployee(employee);
        return "success";
    }

    @ApiOperation("修改员工")
    @PostMapping("/updateEmployee")
    public String updateEmployee(@RequestBody zttEmployee employee){
        employeeService.updateEmployee(employee);
        return "success";
    }

    @PostMapping("/getEmployeeByName")
    public zttEmployee getEmployeeByName(@RequestBody zttEmployee employee) {
        return employeeService.getEmployeeByName(employee);
    }

    @PostMapping("/getEmployeeById")
    public zttEmployee getEmployeeById(@RequestBody zttEmployee EmployeeID) {
        return employeeService.getEmployeeById(EmployeeID);
    }


    @PostMapping("/deleteEmployee")
    public String deleteEmployee(@RequestBody zttEmployee employee) {

        try{

            employeeService.deleteEmployee(employee);
        }catch (Exception e){
            return "error";
        }
        return "success";
    }
}
